﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Authentication.Data.DataContextStorage
{
    public class HttpDataContextStorageContainer : IDataContextStorageContainer
    {
        private string dataContextKey = "DataContext";

        public AuthenticationEntities GetDataContext()
        {
            AuthenticationEntities objectContext = null;
            if (HttpContext.Current.Items.Contains(dataContextKey))
            {
                objectContext = (AuthenticationEntities)HttpContext.Current.Items[dataContextKey];
            }

            return objectContext;
        }

        public void Store(AuthenticationEntities authentication)
        {
            if (HttpContext.Current.Items.Contains(dataContextKey))
                HttpContext.Current.Items[dataContextKey] = authentication;
            else
                HttpContext.Current.Items.Add(dataContextKey, authentication);
        }
    }
}
